using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Data.Filtering;
using DevExpress.XtraGrid.Views.Base;

namespace ChuanPlus.FormControl
{
    public partial class ControlViewRejection : DevExpress.XtraEditors.XtraUserControl
    {
        public ControlViewRejection()
        {
            InitializeComponent();
            dateFrom.DateTime = dateTo.DateTime = DateTime.Today;
            GetFilterResult(dateFrom.DateTime, dateTo.DateTime);
        }

        private void buttonGo_Click(object sender, EventArgs e)
        {
            GetFilterResult(dateFrom.DateTime,dateTo.DateTime);
        }
        private void GetFilterResult(DateTime from, DateTime to)
        {
            xpColRejection.Criteria = new BetweenOperator("RejectDate", from, to);
        }

        private void gridView3_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.Column.FieldName == "Total" && e.IsGetData) e.Value =
             getTotalValue(sender as ColumnView, e.ListSourceRowIndex);
        }
        // Returns the total amount for a specific row.
        private decimal getTotalValue(ColumnView view, int listSourceRowIndex)
        {
            Rejection rejection = (Rejection)gridView1.GetFocusedRow();
            DevExpress.Xpo.XPCollection<RejectionDetails> xpDetails = rejection.RejectionDetails;
            RejectionDetails d = xpDetails[listSourceRowIndex];
            return Convert.ToDecimal(d.UnitPrice * d.Quantity + d.VAT);
        }
    }
}
